#include <ntifs.h>
#include <ntimage.h>
#include "Function.h"

typedef struct _CODE_LINE
{
	int CodeLength;
	BYTE Code[20];
}CODE_LINE,*PCODE_LINE;

typedef struct _CODE_INFO
{
	int LineCount;
	CODE_LINE CodeLine[1];

}CODE_INFO,*PCODE_INFO;

typedef struct _SERVICE_DESCRIPTOR_TABLE {
	/*
	* Table containing cServices elements of pointers to service handler
	* functions, indexed by service ID.
	*/
	PULONG   ServiceTable;
	/*
	* Table that counts how many times each service is used. This table
	* is only updated in checked builds.
	*/
	PULONG  CounterTable;
	/*
	* Number of services contained in this table.
	*/
	ULONG   TableSize;
	/*
	* Table containing the number of bytes of parameters the handler
	* function takes.
	*/
	PUCHAR  ArgumentTable;
} SERVICE_DESCRIPTOR_TABLE, *PSERVICE_DESCRIPTOR_TABLE;

extern PSERVICE_DESCRIPTOR_TABLE KeServiceDescriptorTable;

BOOLEAN HookFunctionHeader(ULONG_PTR NewFunctionAddress,WCHAR *FunctionName,BOOLEAN bSsdt,ULONG_PTR index,PVOID HookZone,int *patchCodeLen,PVOID *lpRet);

void UnHookFunctionHeader(WCHAR *FunctionName,BOOLEAN bSsdt,ULONG_PTR index, PVOID HookZone, int patchCodeLen);

BOOLEAN HookFunctionMiddle(BYTE *StartAddress,int MaxLength,ULONG_PTR ToAddress,PCODE_INFO CodeInfo,PVOID HookZone,int *patchCodeLen,PVOID *lpRet);

VOID UnHookFunctionMiddle(ULONG_PTR PatchAddress,PVOID HookZone,int PatchCodeLen);

BOOLEAN HookFunctionByHeaderAddress(ULONG_PTR NewFunctionAddress,ULONG_PTR oldFunctionAddress,PVOID HookZone,int *patchCodeLen,PVOID *lpRet);

void UnHookFunctionByHeaderAddress(ULONG_PTR oldFunctionAddress,PVOID HookZone, int patchCodeLen);

BOOLEAN GetFunctionIndexByName(CHAR *lpszFunctionName,int *Index);

ULONG_PTR SeachCode(BYTE *StartAddress,int MaxLength,PCODE_INFO CodeInfo);
